package com.feishi.core.socket.common.lifecycle;

import com.feishi.core.analytic.assembler.BaseAssembler;
import com.feishi.core.socket.common.SocketHandler;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by caixq on 5/14 014.
 */
public class SocketSession<T extends BaseAssembler> {
    private SocketApplication<T> application;
    private Map<String,Object> data=new HashMap<>();
    private SocketHandler<T> socketHandler;

    public SocketSession() {

    }

    public void setAttribute(String name,Object value){
        data.put(name,value);
    }
    public Object getAttribute(String name){
        return data.get(name);
    }
    public void clearAttribute(){
        this.data.clear();
    }

    public SocketSession(SocketApplication<T> application) {
        this.application = application;
    }

    public SocketApplication<T> getApplication() {
        return application;
    }

    public void setApplication(SocketApplication<T> application) {
        this.application = application;
    }

    public void removeAttribute(String key) {
        this.data.remove(key);
    }

    public  void setSocketHandler(SocketHandler<T> socketHandler) {
        this.socketHandler = socketHandler;
    }

    public SocketHandler<T> getSocketHandler() {
        return socketHandler;
    }
    public void write(byte[] bytes){
        socketHandler.write(bytes);
    }

}
